package cn.vpclub.controller;

import cn.vpclub.dao.PersonRepostiries;
import cn.vpclub.entity.Person;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.reactivestreams.Publisher;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

/**
 * Created by kellen on 2017/6/17.
 */
@RestController
@RequestMapping("/person")
@AllArgsConstructor
@Slf4j
public class PersonController {

    private final PersonRepostiries repository;


    @PostMapping(value = "/save")
    public Mono<Person> save(@RequestBody Publisher<Person> personStream) {
        return repository.saveAll(personStream).next();
    }

    @GetMapping("/person/{id}")
    public Mono<Person> findById(@PathVariable String id) {
        return repository.findById(id);
    }

    @GetMapping("/list")
    public Flux<Person> list() {
        return repository.findAll();
    }

}
